//
//  YDMyContactTableViewCell.m
//  IngCard
//
//  Created by kf on 2017/8/13.
//  Copyright © 2017年 IngDan. All rights reserved.
//

#import "YDMyContactTableViewCell.h"

@implementation YDMyContactCellDataSource
-(Class) viewClass
{
    return [YDMyContactTableViewCell class];
}

@end


@interface YDMyContactTableViewCell()
@property(nonatomic, strong) UIImageView *userHeaderView;
@property(nonatomic, strong) UILabel *userNameLabel;
@property(nonatomic, strong) UILabel *userTitleLabel;
@end

@implementation YDMyContactTableViewCell


+(CGFloat)viewHeight:(YDMyContactCellDataSource *) dataSource
{
    return dataSource.height ?:  80;
}


- (void) initSubviews
{
    [super initSubviews];
    [self.contentView addSubview:self.userHeaderView];
    [self.userHeaderView makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(30);
        make.top.equalTo(12);
        make.width.equalTo(60);
        make.height.equalTo(60);
    }];
    
    [self.contentView addSubview:self.userNameLabel];
    [self.userNameLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.userHeaderView.mas_right).offset(39);
        make.top.equalTo(20);
    }];
    
    [self.contentView addSubview:self.userTitleLabel];
    [self.userTitleLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.userNameLabel);
        make.top.equalTo(self.userNameLabel.mas_bottom).offset(1);
        make.right.equalTo(self.contentView).offset(-8);
    }];
}

-(void) onViewModelChanged
{
    YDMyContactCellDataSource *dataSource = (YDMyContactCellDataSource *)self.dataSource;
    if (dataSource)
    {
        UIImageViewSetUrl(self.userHeaderView, dataSource.headerImageUrl);
        self.userNameLabel.text = dataSource.userName;
        self.userTitleLabel.text = dataSource.userTitle;
    }
}

#pragma mark - Lazy loading

-(UIImageView *) userHeaderView
{
    if (!_userHeaderView)
    {
        _userHeaderView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 60, 60)];
        _userHeaderView.image = UIImageMake(@"myCardCell_userHeader1");
        _userHeaderView.layer.cornerRadius = 30;
        _userHeaderView.layer.masksToBounds = YES;
        _userHeaderView.contentMode = UIViewContentModeScaleToFill;
        [_userHeaderView sizeToFit];
    }
    return _userHeaderView;
}

-(UILabel *) userNameLabel
{
    if (!_userNameLabel)
    {
        _userNameLabel = [[UILabel alloc] init];
        _userNameLabel.text = @"Andrea Berry";
        _userNameLabel.textAlignment = NSTextAlignmentLeft;
        _userNameLabel.font = UIFontLightMake(15);
        _userNameLabel.textColor = UIColorMake(0, 0, 0);
        [_userNameLabel sizeToFit];
    }
    return _userNameLabel;
}

-(UILabel *) userTitleLabel
{
    if (!_userTitleLabel)
    {
        _userTitleLabel = [[UILabel alloc] init];
        _userTitleLabel.text = @"LinkedIn，VP";
        _userTitleLabel.textAlignment = NSTextAlignmentLeft;
        _userTitleLabel.font = UIFontLightMake(15);
        _userTitleLabel.textColor = UIColorMake(0, 0, 0);
        [_userTitleLabel sizeToFit];
    }
    return _userTitleLabel;
}



@end
